<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-assets-edit" th:object="${assets}">
            <input id="assetsId" name="assetsId" th:field="*{assetsId}"  type="hidden">
            <input name="deptId"  type="hidden"  th:field="*{deptId}" id="treeId"/>
            <div class="form-group">
                <label class="col-sm-3 control-label">门店名称：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="deptName" onclick="selectDeptTree()" readonly="true" id="treeName" th:field="*{deptName}">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">名称：</label>
                <div class="col-sm-8">
                    <input id="assetsName" name="assetsName" th:field="*{assetsName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">是否在使用中：</label>
                <div class="col-sm-8">
                    <select id="state" class="form-control m-b" th:with="type=${@dict.getType('zl_song_shiyong')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{state}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input id="remark" name="remark" th:field="*{remark}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">是否损坏：</label>
                <div class="col-sm-8">
                    <select id="available" class="form-control m-b" th:with="type=${@dict.getType('zl_song_gang')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{available}"></option>
                    </select>
                </div>
            </div>

            <div class="form-group">	
                <label class="col-sm-3 control-label">创建时间：</label>
                <div class="col-sm-8">
                    <input id="creatTime" name="creatTime" th:field="*{creatTime}" class="form-control" type="text">
                </div>
            </div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "project/assets"
		$("#form-assets-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});

        function submitHandler() {
            if ($.validate.form()) {
                edit();
            }
        }

        function edit() {

            var assetsId = $("input[name='assetsId']").val();
            var deptId = $("input[name='deptId']").val();
            var deptName = $("input[name='deptName']").val();
            var assetsName = $("input[name='assetsName']").val();
            var remark = $("input[name='remark']").val();
            var creatTime = $("input[name='creatTime']").val();
            var state = $("#state option:selected").val();
            var available = $("#available option:selected").val();

            $.ajax({
                cache : true,
                type : "POST",
                url : ctx + "project/assets/edit",
                data : {
                    "assetsId":assetsId,
                    "deptId":deptId,
                    "deptName":deptName,
                    "assetsName":assetsName,

                    "remark":remark,

                    "creatTime":creatTime,
                    "state": state,
                    "available": available

                },
                async : false,
                error : function(request) {
                    $.modal.alertError("系统错误");
                },
                success : function(data) {
                    $.operate.saveSuccess(data);
                }
            });
        }

        /*用户管理-新增-选择部门树*/
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: ctx + "system/dept/selectDeptTree/" + deptId,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }
        }
	</script>
</body>
</html>
